import type { App } from 'vue'
import moment from 'moment'
import { store } from '../store'
import { intersection } from 'lodash-es'
export default (app: App) => {
// 权限指令，store.state.identity为接口返回的身份权限
// binding.value为该btn自身的身份权限
// 当两个数组有交集时说明该登录的身份符合按钮的显示条件
  app.directive('permission', {
    mounted (el, binding) {
      if (binding.value?.length) {
        const isShow = intersection(binding.value, store.state.identity)?.length
        el.style.display = isShow ? '' : 'none'
      }
    }
  })
  app.directive('time', {
    mounted (el, binding) {
      const time = moment(el.textContent.ISO_8601).format('YY-MM-DD')
      el.textContent = time
    }
  })
}
